package edu.hawaii.halealohacli.processor;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;

/**
 * A JUnit test for testing the Processor for correctness.
 * 
 * @author Chris Fang
 */
public class TestProcessor {

  Processor testProcessor;
  String error;

  /**
   * Create a Processor to test.
   */
  public TestProcessor() {
    String url = "http://server.wattdepot.org:8190/wattdepot/";
    testProcessor = new Processor(new WattDepotClient(url));
  }

  /**
   * Test processInput method for correct handling of inputs.
   */
  @Test
  public void testSetTesting() {
    error = "testSetTesting failed: Expected true";
    assertTrue(error, testProcessor.setTesting(true));
    error = "testSetTesting failed: Expected false";
    assertFalse(error, testProcessor.setTesting(false));
  }

  /**
   * Test processInput method for correct handling of inputs.
   */
  @Test
  public void testProcessInput() {
    testProcessor.setTesting(true);
    error = "testProcessInput failed: \"daily-energy\" not recognized";
    assertEquals(error, testProcessor.processInput("daily-energy Ilima 2011-11-25"),
        Processor.COMMAND);
    error = "testProcessInput failed: \"DAILY-ENERGY\" not recognized";
    assertEquals(error, testProcessor.processInput("DAILY-ENERGY Ilima 2011-11-25"),
        Processor.COMMAND);
    error = "testProcessInput failed: \"rank-towers\" not recognized";
    assertEquals(error, testProcessor.processInput("rank-towers 2011-11-23 2011-11-25"),
        Processor.COMMAND);
    error = "testProcessInput failed: \"RANK-TOWERS\" not recognized";
    assertEquals(error, testProcessor.processInput("RANK-TOWERS 2011-11-23 2011-11-25"),
        Processor.COMMAND);
    error = "testProcessInput failed: \"help\" not recognized";
    assertEquals(error, testProcessor.processInput("help"), Processor.HELP);
    error = "testProcessInput failed: \"HELP\" not recognized";
    assertEquals(error, testProcessor.processInput("HELP"), Processor.HELP);
    error = "testProcessInput failed: \"quit\" not recognized";
    assertEquals(error, testProcessor.processInput("quit"), Processor.QUIT);
    error = "testProcessInput failed: \"QUIT\" not recognized";
    assertEquals(error, testProcessor.processInput("QUIT"), Processor.QUIT);
    error = "testProcessInput failed: incorrect input not recognized as error";
    assertEquals(error, testProcessor.processInput("error"), Processor.ERROR);
  }

  /**
   * Test buildHelpMessage method for correctness.
   */
  @Test
  public void testBuildHelpMessage() {
    testProcessor.setTesting(true);
    error = "testBuildHelpMessage failed: Help message does not contain all expected values";
    assertTrue(error, testProcessor.buildHelpMessage().contains("Available"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("quit"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("execution"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("Note:"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("Mokihana"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("Lounges"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("followed"));
    assertTrue(error, testProcessor.buildHelpMessage().contains("For"));
  }

  /**
   * Test getHelpMessage method for correctness.
   */
  @Test
  public void testGetHelpMessage() {
    testProcessor.setTesting(true);
    error = "testGetHelpMessage failed: Help message does not contain all expected values";
    assertTrue(error, testProcessor.getHelpMessage().contains("Available"));
    assertTrue(error, testProcessor.getHelpMessage().contains("quit"));
    assertTrue(error, testProcessor.getHelpMessage().contains("execution"));
    assertTrue(error, testProcessor.getHelpMessage().contains("Note:"));
    assertTrue(error, testProcessor.getHelpMessage().contains("Mokihana"));
    assertTrue(error, testProcessor.getHelpMessage().contains("Lounges"));
    assertTrue(error, testProcessor.getHelpMessage().contains("followed"));
    assertTrue(error, testProcessor.getHelpMessage().contains("For"));
  }
}
